﻿<?php
	
	#
	# Garlic PHP/0.10
	# Copyleft (C) 2010 By Philip Patrick Butkiewicz (Bagno/Yuuki) and others (see "AUTHORS")
	# Project website: http://code.google.com/p/garlic-php
	#
	
	class garlicMySQL {
	
		private $_db, $_q;
	
		#	Construct class and connect to MySQL...
		public function __construct((string)$host, (string)$user, (string)$passw) {
			$this->_db = mysql_connect($host, $user, $passw);
			if (!$this->_db) {
				return false;
			}
			else {
				return true;
			}
		}
		
		#	Used for selecting database
		public function selectdb((string)$db) {
			if (mysql_select_db($db, $this->_db)) {
				return true;
			}
			else {
				return false;
			}
		}
		
		#	Use to perform query and get array with data
		public function query((string)$query)
		{
			$this->_q = mysql_query($query);
			if (!$this->_q) {
				return false;
			}
			
			return mysql_fetch_assoc($this->_q);
		}
		
		#	Use to count stuff
		public function count((bool)$rows)
		{
			if (!$this->_q) {
				return false;
			}
			
			if ($rows) {
				return mysql_num_rows($this->_q);
			}
			else {
				return mysql_num_fields($this->_q);
			}
		}
		
		public function __destruct() {
			mysql_close($this->_db);
		}
	}
?>